#define _CRT_SECURE_NO_WARNINGS 1

//#include <iostream>
//using namespace std;
//int main()
//{
//    cout << "A C" << endl;
//    cout << "A D" << endl;
//    cout << "B D" << endl;
//    return 0;
//}



#include<bits/stdc++.h>

using namespace std;

int dx[8] = { 1,-1,0,0,1,-1,1,-1 };
int dy[8] = { 0,0,1,-1,-1,-1,1,1 };

int main()
{
	int m, n;
	cin >> m >> n;

	vector<vector<int>> grid(m, vector<int>(n));
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> grid[i][j];
			if (grid[i][j] == 1)
				grid[i][j] = 9;
		}
	}

	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (grid[i][j] == 0)
			{
				int tmp = 0;
				for (int k = 0; k < 8; k++)
				{
					int x = i + dx[k];
					int y = j + dy[k];
					if (x >= 0 && y >= 0 && x < m && y < n && grid[x][y] == 9)
						tmp++;
				}
				grid[i][j] = tmp;
			}
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << grid[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}